package com.cskaoyan.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * Vo viewObject
 * @param <T>
 * 这是前后端分离，json数据一个常用的格式
 */
@Data
public class BaseRespVo<T> {
    @JsonInclude(JsonInclude.Include.NON_NULL)
    T data;
    String errmsg;//告诉前端请求的消息
    Integer errno;//自己的前后端应用 ： 自定义的状态码 → 通常前端根据该状态码做不同的处理

    public static BaseRespVo ok(){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }
    public static BaseRespVo ok(Object data){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(data);
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }
    public static BaseRespVo ok(Object data, String errmsg){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setData(data);
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg(errmsg);
        return baseRespVo;
    }
    public static BaseRespVo fail(){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(500);
        baseRespVo.setErrmsg("失败");
        return baseRespVo;
    }
    public static BaseRespVo fail(String errmsg){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(500);
        baseRespVo.setErrmsg(errmsg);
        return baseRespVo;
    }
    public static BaseRespVo fail601(){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(601);
        baseRespVo.setErrmsg("管理员名称不符合规定");
        return baseRespVo;
    }
    public static BaseRespVo fail602(){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(602);
        baseRespVo.setErrmsg("密码长度不能小于6");
        return baseRespVo;
    }

    public static BaseRespVo fail605(){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(605);
        baseRespVo.setErrmsg("用户帐号或密码不正确");
        return baseRespVo;
    }
    public static BaseRespVo fail501(){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(501);
        baseRespVo.setErrmsg("请登录");
        return baseRespVo;
    }

    public static BaseRespVo fail642() {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(642);
        baseRespVo.setErrmsg("当前角色存在管理员，不能删除");
        return baseRespVo;
    }
    public static BaseRespVo fail700() {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(700);
        baseRespVo.setErrmsg("账号密码不对");
        return baseRespVo;
    }
    public static BaseRespVo fail402() {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(402);
        baseRespVo.setErrmsg("参数值不对");
        return baseRespVo;
    }
}
